﻿
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "GbmpNew.h"
#include "UniIdentity.h"
#include "IParameterValueList.h"
#include "IParameterValueStorage.h"

#include "ParameterDisplayColorList.h"
#include "ParameterDisplayDropdownList.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gcmp;
using namespace Sample;

ParameterDisplayColorList::ParameterDisplayColorList(const UniIdentity& uid, OwnerPtr<IParameterValueList> oValueList, std::wstring externalDisplayString /*= L""*/)
{
    m_dropDownListImpl = NEW_AS_OWNER_PTR(ParameterDisplayDropdownList, uid, TransferOwnership(oValueList));
    if (externalDisplayString == L"")
    {
        m_externalDisplayString = L"更多";
    }
    else
    {
        m_externalDisplayString = externalDisplayString;
    }
}

ParameterDisplayColorList::ParameterDisplayColorList( const ParameterDisplayColorList &other )
{
    if (other.m_dropDownListImpl != nullptr)
    {
        m_dropDownListImpl = NEW_AS_OWNER_PTR(ParameterDisplayDropdownList, *other.m_dropDownListImpl);
    }
    m_externalDisplayString = other.m_externalDisplayString;
}

ParameterDisplayColorList& ParameterDisplayColorList::operator=( const ParameterDisplayColorList &other )
{
    if (this != &other)
    {
        if (other.m_dropDownListImpl != nullptr)
        {
            m_dropDownListImpl = NEW_AS_OWNER_PTR(ParameterDisplayDropdownList, *other.m_dropDownListImpl);
        }
        m_externalDisplayString = other.m_externalDisplayString;
    }

    return *this;
}

ParameterDisplayColorList::~ParameterDisplayColorList()
{

}

std::wstring ParameterDisplayColorList::GetDisplayStringByValue(const IDocument* pDoc, const IParameterValueStorage* pValue) const
{
    std::wstring res;
    DBG_WARN_AND_RETURN_UNLESS(m_dropDownListImpl, res, L"m_dropDownListImpl为空！",L"GDMP",L"2023-10-20");

    res = m_dropDownListImpl->GetDisplayStringByValue(pDoc, pValue);
    return res;
}

OwnerPtr<IParameterValueStorage> ParameterDisplayColorList::GetValueByDisplayString(const IDocument* pDoc, const std::wstring& displayString, const std::vector<ElementId>& ids) const
{
    OwnerPtr<IParameterValueStorage> oRes;
    DBG_WARN_AND_RETURN_UNLESS(m_dropDownListImpl, oRes, L"m_dropDownListImpl为空！",L"GDMP",L"2023-10-20");

    if (displayString == m_externalDisplayString)
    {
        return oRes;
    }

    oRes = m_dropDownListImpl->GetValueByDisplayString(pDoc, displayString, ids);
    return oRes;
}

std::vector<std::wstring> ParameterDisplayColorList::GetDisplayStrings(const IDocument* pDoc, const std::vector<ElementId>& ids) const
{
    std::vector<std::wstring> res;
    DBG_WARN_AND_RETURN_UNLESS(m_dropDownListImpl, res, L"m_dropDownListImpl为空！",L"GDMP",L"2023-10-20");

    res = m_dropDownListImpl->GetDisplayStrings(pDoc, ids);
    res.push_back(m_externalDisplayString);
    return res;
}

//bool gcmp::ParameterDisplayColorList::SetExternalItemDiaplayString(const std::wstring &displayString)
//{
//    m_externalDisplayString = displayString;
//    return true;
//}
//
//std::wstring gcmp::ParameterDisplayColorList::GetExternalItemDiaplayString() const
//{
//    return m_externalDisplayString;
//}

std::vector<OwnerPtr<IParameterValueStorage>> ParameterDisplayColorList::GetValues(const IDocument* pDoc, const std::vector<ElementId>& ids) const
{
    std::vector<OwnerPtr<IParameterValueStorage>> res;
    DBG_WARN_AND_RETURN_UNLESS(m_dropDownListImpl, res, L"m_dropDownListImpl为空！",L"GDMP",L"2023-10-20");

    res = m_dropDownListImpl->GetValues(pDoc, ids);
    return res;
}

const IParameterValueList* ParameterDisplayColorList::GetParameterValueList() const
{
    return m_dropDownListImpl->GetParameterValueList();
}

const UniIdentity& ParameterDisplayColorList::GetParameterDefinitionUid() const
{
    return m_dropDownListImpl->GetParameterDefinitionUid();
}

bool ParameterDisplayColorList::IsManualInputModifiable(const IDocument* pDoc) const
{
    return false;
}

